package com.sharp.kernel.mybatis.repository;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sharp.kernel.mybatis.join.entity.IOutJoinRelationship;
import com.sharp.kernel.mybatis.mapper.OuterJoinMapper;
import com.sharp.kernel.mybatis.repository.inf.SqlOuterJoinRepository;
import com.sharp.kernel.utils.DbUtil;
import org.apache.ibatis.session.RowBounds;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * Title: BaseOuterJoinRepository
 * Description: Copyright: Copyright (c) 2019 Company: BHFAE
 *
 * @author Sharp
 * @date 2022/7/27 9:20
 */
public class BaseOuterJoinRepository<T extends IOutJoinRelationship, K extends OuterJoinMapper<T>> extends BaseMybatisRepository<T, K> implements SqlOuterJoinRepository<T> {

    @Override
    public PageInfo<T> select(Example example, int currentPage, int pageSize) {
        PageInfo<T> pageInfo = DbUtil.buildPageInfo(currentPage, pageSize, entityClass);
        PageHelper.startPage(pageInfo);
        return new PageInfo<>(select(example));
    }

    @Override
    public List<T> select(Example example) {
        return getDao().outerJoinSelectByExample(example);
    }

    @Override
    public PageInfo<T> select(Example example, PageInfo<T> pageInfo) {
        PageHelper.startPage(pageInfo);
        return new PageInfo<>(select(example));
    }
}
